package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.events.vo.BriskWalkAnswerQuestionVO;
import net.maku.events.vo.KnowledgeAnswerQuestionVO;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.events.service.ActivityKnowledgeContestService;
import net.maku.events.query.ActivityKnowledgeContestQuery;
import net.maku.events.vo.ActivityKnowledgeContestVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 知识竞赛活动
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-22
 */
@RestController
@RequestMapping("events/activity_knowledge_contest")
@Tag(name = "知识竞赛活动")
@AllArgsConstructor
public class ActivityKnowledgeContestController {
    private final ActivityKnowledgeContestService activityKnowledgeContestService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('events:activity_knowledge_contest:page')")
    public Result<PageResult<ActivityKnowledgeContestVO>> page(@ParameterObject @Valid ActivityKnowledgeContestQuery query) {
        PageResult<ActivityKnowledgeContestVO> page = activityKnowledgeContestService.page(query);

        return Result.ok(page);
    }

    @GetMapping("/join/{id}")
    @Operation(summary = "参与活动")
    public Result<String> joinActivity(@PathVariable("id") Long id) {
        activityKnowledgeContestService.joinActivity(id);
        return Result.ok();
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('events:activity_knowledge_contest:info')")
    public Result<ActivityKnowledgeContestVO> get(@PathVariable("id") Long id) {
        return Result.ok(activityKnowledgeContestService.getInfoById(id));
    }

    @PostMapping("/answer")
    @Operation(summary = "知识竞赛答题")
    public Result<Double> answer(@RequestBody KnowledgeAnswerQuestionVO vo) {
        return Result.ok(activityKnowledgeContestService.answer(vo));
    }


}